package com.icez.videoplay.core

import android.app.Activity
import android.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.google.android.youtube.player.YouTubePlayer
import com.google.android.youtube.player.YouTubePlayerFragment
import com.icez.videoplay.R

class YoutubePlayManager {
    companion object{
        val instance:YoutubePlayManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED){
            YoutubePlayManager()
        }
        var playerFragment: YouTubePlayerFragment?= null
    }

    public fun initConfig(
        mActivity: Activity,
        apiKey: String,
        mOnInitializedListener: YouTubePlayer.OnInitializedListener){

        if(playerFragment!=null){
            mActivity.getFragmentManager().beginTransaction().remove(playerFragment).commit()
        }
        playerFragment = YouTubePlayerFragment.newInstance()
        playerFragment?.initialize(apiKey, mOnInitializedListener)
        mActivity.getFragmentManager().beginTransaction().add(R.id.youtube_framelayout, playerFragment).commit()

    }




}